package com.hpq.user.controller;

import com.hpq.common.domain.vo.response.ApiResult;
import com.hpq.common.utils.AssertUtil;
import com.hpq.common.utils.RequestHolder;
import com.hpq.user.domain.enums.RoleEnum;
import com.hpq.user.domain.vo.request.user.BlackReq;
import com.hpq.user.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 *  黑名单管理相关接口
 */
@RestController
@RequestMapping("/capi/user")
@Api(tags ="黑名单管理相关接口")
@Slf4j
public class BlackController {
    @Autowired
    private RoleService roleService;
    @PutMapping("/black")
    @ApiOperation(value = "拉黑用户")
    public ApiResult<Void> black(@Valid @RequestBody BlackReq req){
        Long uid = RequestHolder.get().getUid();
        boolean hasPower = roleService.hasPower(uid, RoleEnum.ADMIN);
        AssertUtil.isNotTrue(hasPower,"没有权限使用此操作");
        roleService.black(req);
        return ApiResult.success();

    }
}
